package com.gitee.jmliu1983.finacehelper.controller;

import java.util.List;
import java.io.IOException;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
//import com.ruoyi.common.log.annotation.Log;
//import com.ruoyi.common.log.enums.BusinessType;
//import com.ruoyi.common.security.annotation.RequiresPermissions;
import com.gitee.jmliu1983.finacehelper.domain.TransactionsFund;
import com.gitee.jmliu1983.finacehelper.service.ITransactionsFundService;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
//import com.ruoyi.common.core.web.controller.BaseController;
//import com.ruoyi.common.core.web.domain.AjaxResult;
//import com.ruoyi.common.core.utils.poi.ExcelUtil;
//import com.ruoyi.common.core.web.page.TableDataInfo;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;

/**
 * 个人持仓记录Controller
 * 
 * @author ruoyi
 * @date 2025-02-27
 */
@RestController
@RequestMapping("/transactions_fund")
@PreAuthorize("@ss.hasRole('finace')")
public class TransactionsFundController extends BaseController
{
    @Autowired
    private ITransactionsFundService transactionsFundService;

    /**
     * 查询个人持仓记录列表
     */
//    @RequiresPermissions("finace:transactions_fund:list")
    @GetMapping("/list")
    public TableDataInfo list(TransactionsFund transactionsFund)
    {
        startPage();
        List<TransactionsFund> list = transactionsFundService.selectTransactionsFundList(transactionsFund);
        return getDataTable(list);
    }

    /**
     * 导出个人持仓记录列表
     */
//    @RequiresPermissions("finace:transactions_fund:export")
    @Log(title = "个人持仓记录", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, TransactionsFund transactionsFund)
    {
        List<TransactionsFund> list = transactionsFundService.selectTransactionsFundList(transactionsFund);
        ExcelUtil<TransactionsFund> util = new ExcelUtil<TransactionsFund>(TransactionsFund.class);
        util.exportExcel(response, list, "个人持仓记录数据");
    }

    /**
     * 获取个人持仓记录详细信息
     */
//    @RequiresPermissions("finace:transactions_fund:query")
    @GetMapping(value = "/{transactionId}")
    public AjaxResult getInfo(@PathVariable("transactionId") Long transactionId)
    {
        return success(transactionsFundService.selectTransactionsFundByTransactionId(transactionId));
    }

    /**
     * 新增个人持仓记录
     */
//    @RequiresPermissions("finace:transactions_fund:add")
    @Log(title = "个人持仓记录", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody TransactionsFund transactionsFund)
    {
        return toAjax(transactionsFundService.insertTransactionsFund(transactionsFund));
    }

    /**
     * 修改个人持仓记录
     */
//    @RequiresPermissions("finace:transactions_fund:edit")
    @Log(title = "个人持仓记录", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody TransactionsFund transactionsFund)
    {
        return toAjax(transactionsFundService.updateTransactionsFund(transactionsFund));
    }

    /**
     * 删除个人持仓记录
     */
//    @RequiresPermissions("finace:transactions_fund:remove")
    @Log(title = "个人持仓记录", businessType = BusinessType.DELETE)
	@DeleteMapping("/{transactionIds}")
    public AjaxResult remove(@PathVariable Long[] transactionIds)
    {
        return toAjax(transactionsFundService.deleteTransactionsFundByTransactionIds(transactionIds));
    }
}
